<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <link rel="stylesheet" href="assets/mui/css/mui.min.css">
    <link rel="stylesheet" href="assets/fontAwesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="css/base.css">
    <script src="assets/zepto/zepto.min.js"></script>
    <script src="assets/mui/js/mui.js"></script>
    <script src="./js/common.js"></script>
    <style>
        .list {
            margin-top: 0px;
        }

        .logout {
            text-align: center;
        }

        li {
            border-bottom: 1px solid #ccc;
        }

        .mui-table-view-cell:after {
            height: 0;
        }

    </style>
</head>

<body>
    <header class="mui-bar mui-bar-nav header">
        <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" href="javascript:history.back(-1)"></a>
        <h1 class="mui-title">个人中心</h1>
        <a class="mui-icon mui-icon-search mui-pull-right"></a>

    </header>
    <nav class="mui-bar mui-bar-tab footer">
        <a class="mui-tab-item mui-active" href="index.html">
            <span class="mui-icon mui-icon-home"></span>
            <span class="mui-tab-label">首页</span>
        </a>
        <a class="mui-tab-item" href="category.html">
            <span class="mui-icon mui-icon-bars"></span>
            <span class="mui-tab-label">分类</span>
        </a>
        <a class="mui-tab-item" href="cart.html">
            <span class="mui-icon fa fa-shopping-cart"></span>
            <span class="mui-tab-label">购物车</span>
        </a>
        <a class="mui-tab-item  mui-active" href="user.html">
            <span class="mui-icon mui-icon-person"></span>
            <span class="mui-tab-label">会员中心</span>
        </a>
    </nav>
    <div class="mui-content">
        <ul class="mui-table-view list">
            <li class="mui-table-view-cell mui-media userMsg">

            </li>
            <li class="mui-table-view-cell">
                <a class="mui-navigate-right" href="changePwd.html">修改密码</a>
            </li>
            <li class="mui-table-view-cell">
                <a class="mui-navigate-right" href="myCart.html">我的购物车</a>
            </li>
            <li class="mui-table-view-cell">
                <a class="mui-navigate-right" href="address.html">收获地址管理</a>
            </li>
            <li class="mui-table-view-cell logout">
                <a href="#">退出登录</a>
            </li>
        </ul>
    </div>
</body>
<script src="./assets/artTemplate/template-web.js"></script>
<script type="text/template" id="user">
    <a href="javascript:;">
    <img class="mui-media-object mui-pull-left" src="./images/user.jpg">
    <div class="mui-media-body mui-navigate-right">
        {{mobile}}
<p class='mui-ellipsis'>账号：{{username}}</p>
    </div>
</a>
</script>
<script>
    $.ajax({
        url: '/user/queryUserMessage',
        type: "GET",
        success: function (res) {
            if (res.error && res.error == 400) {
                mui.toast('用户未登录')
                location.href = 'login.html'
            } else {
                var html = template('user', res)
                $('.userMsg').html(html)
                console.log(html)
            }
        }
    })
    $('.logout').on('tap', function () {
        $.ajax({
            url: '/user/logout',
            type: 'GET',
            success: function (res) {
                if (res.success) {
                    mui.toast('成功退出')
                    setTimeout(() => {

                        location.href = 'login.html'
                    }, 1000);
                } else if (res.error) {
                    mui.toast(res.message)
                }
            }
        })
    })

</script>

</html>
